<template>
	<div class="zy-content">
		<div class="tenace_box">
			<div class="box_content">
				<div class="serachBox search-box-layout">
					<Row style="width: 100%">
						<Form label-position="top" class="search-form">
							<Row>
								<Col span="6">
									<FormItem :label="$t('common.Installation')">
										<Cascader placeholder="请选择" :data="orgList" v-model="searchParams.installPositionStr"> </Cascader>
									</FormItem>
								</Col>
								<Col span="6">
									<FormItem :label="$t('maintenance.EquipmentName')">
										<Input
											type="text"
											clearable
											v-model="searchParams.deviceName"
											:placeholder="`${$t('common.inputInfo')}`"
											class="inputBorder"
											:maxlength="32"
										></Input>
										<!-- <Select
                      v-model="searchParams.deviceName"
                      filterable
                      :transfer="true"
                      clearable
                      :remote-method="getDeviceNameList"
                      :placeholder="`${$t('common.selectInfo')}`"
                    >
                      <Option
                        v-for="item of deviceNameList"
                        :value="item.value"
                        :label="item.label"
                        :key="item.value"
                      >
                      </Option>
                    </Select> -->
									</FormItem>
								</Col>
								<Col span="6">
									<FormItem :label="$t('maintenance.EquipmentNo')">
										<Input
											type="text"
											clearable
											v-model="searchParams.deviceNo"
											:placeholder="`${$t('common.inputInfo')}`"
											class="inputBorder"
											:maxlength="32"
										></Input>
									</FormItem>
								</Col>
								<Col span="6">
									<FormItem :label="$t('设备等级')">
										<Select v-model="searchParams.deviceGrade" filterable :transfer="true" clearable :placeholder="`${$t('common.selectInfo')}`">
											<Option v-for="item of centerList" :value="item.value" :key="item.value" :label="item.label"> </Option>
										</Select>
									</FormItem>
								</Col>
								<Col span="6">
									<FormItem :label="$t('设备类别')">
										<Select v-model="searchParams.deviceType" filterable clearable :placeholder="`${$t('common.selectInfo')}`">
											<Option v-for="item in deviceTypeList" :value="item.value" :key="item.value" :label="item.value" />
										</Select>
									</FormItem>
								</Col>
								<Col span="6">
									<FormItem label="点检计划">
										<Select
											v-model="searchParams.planId"
											filterable
											clearable
											:transfer="true"
											:placeholder="`${$t('common.inputInfo')}`"
											:remote-method="getCenterList"
										>
											<Option v-for="(item, index) of planList" :value="item.value" :key="index" :label="item.label"> </Option>
										</Select>
									</FormItem>
								</Col>
								<Col span="6">
									<FormItem label="点检级别">
										<Select v-model="searchParams.planLevel" clearable :transfer="true" :placeholder="`${$t('common.selectInfo')}`">
											<Option v-for="item of levelList" :value="item.key" :label="item.name" :key="item.key"> </Option>
										</Select>
									</FormItem>
								</Col>
								<Col span="6">
									<FormItem :label="$t('maintenance.TaskDate')">
										<DatePicker
											:value="dateTimeRange"
											type="daterange"
											:transfer="true"
											placement="bottom-end"
											:placeholder="`${$t('common.selectInfo')}`"
											@on-change="handleRangeChange"
										/>
									</FormItem>
								</Col>
								<Col span="6">
									<FormItem :label="$t('maintenance.MaintenanceBy')">
										<Select
											v-model="searchParams.operater"
											filterable
											clearable
											:transfer="true"
											:placeholder="`${$t('common.inputInfo')}`"
											@on-query-change="timeOutgetUserNo"
										>
											<Option v-for="(item, index) of userNoArr" :value="item.empno" :key="index" :label="item.empno + '-' + item.realname"> </Option>
										</Select>
									</FormItem>
								</Col>
								<Col span="6">
									<FormItem :label="$t('点检类型')">
										<Select clearable :transfer="true" @on-change="swipeClick" v-model="typeInfo">
											<Option v-for="item in targetCirlelist" :value="item.text" :label="item.text" :key="item.text"> </Option>
										</Select>
									</FormItem>
								</Col>
								<Col span="6">
									<FormItem :label="$t('设备流水号')">
										<Select
											v-model="searchParams.deviceMId"
											filterable
											clearable
											:placeholder="`${$t('common.inputInfo')}${$t('equipCheck.SerialNo')}`"
											:remote-method="handleRemote"
										>
											<Option v-for="item in deviceMIdList" :value="item.deviceMId" :label="item.desc" :key="item.deviceMId" />
										</Select>
									</FormItem>
								</Col>
								<Col span="6">
									<FormItem :label="$t('点检单号')">
										<Input type="text" clearable v-model="searchParams.taskNo" :placeholder="`${$t('common.inputInfo')}`" class="inputBorder" />
									</FormItem>
								</Col>
								<div style="width: 100%; padding-top: 5px; display: flex; justify-content: center; align-items: center">
									<Button type="primary" class="search-btn" @click="assetsChange" style="margin-right: 10px">
										{{ $t('common.Query') }}
									</Button>
									<Button class="reset-btn" @click="reset" style="margin-right: 10px">
										{{ $t('common.reset') }}
									</Button>
									<template v-if="activeTab === `${$t('maintenance.Tobeallocated')}`">
										<template v-if="idsList && idsList.length">
											<Button class="search-btn" style="margin-right: 10px" @click="handleBatchDispatch">
												{{ $t('maintenance.BatchDistribution') }}
											</Button>
										</template>
									</template>
									<template v-if="activeTab === '待点检'">
										<template v-if="idsList && idsList.length">
											<Button style="margin-right: 10px" class="search-btn" @click="handleBatchTransfer">
												{{ $t('fault.TransferOrderMach') }}
											</Button>
										</template>
									</template>
									<template v-if="idsList && idsList.length">
										<Button class="search-btn" @click="handleBatchDelete">
											{{ $t('common.batchDelete') }}
										</Button>
									</template>
								</div>
							</Row>
						</Form>
					</Row>
				</div>
				<Tabs :value="activeTab" @on-click="tabChange" class="content_tab tabs-layout" animated>
					<TabPane
						v-for="item in tabList"
						:name="item.title"
						:label="
							(h) => {
								return h('div', [
									h('span', item.title),
									h('Badge', {
										props: {
											count: item.num,
										},
									}),
								]);
							}
						"
						:key="item.title"
					>
						<div class="serachBoxMain orderList">
							<div class="wrap" v-if="listArr && listArr.length">
								<div class="item" v-for="(list, index) in listArr" :key="index">
									<div class="name">
										<span>{{ list.deviceNo }}</span>
									</div>
									<div style="display: flex; justify-content: flex-start; align-items: center; height: 26px">
										<span class="tag_item text">{{ list.deviceName }}</span>
									</div>
									<div style="justify-content: flex-start; height: 40px">
										<span class="tag_item">
											<Tag color="yellow" class="tag_item">{{ list.planLevel }}</Tag>
										</span>
										<span class="tag_item">
											<Tag color="blue" class="tag_item">{{ list.cycleUnit }}</Tag>
										</span>
										<span class="tag_item">
											<Tag color="blue" class="tag_item">{{ list.affirmId ? '需要确认' : '不需要确认' }}</Tag>
										</span>
									</div>
									<div class="details">
										<div class="formItem" v-if="list.realname">
											<div class="label">{{ $t('点检人') }}：</div>
											<div class="value">{{ list.realname }}- {{ list.operateEmpno }}</div>
										</div>
										<div class="formItem">
											<div class="label">{{ $t('计划名称') }}：</div>
											<div class="value">{{ list.planName }}</div>
										</div>
										<div class="formItem">
											<div class="label">{{ $t('点检单号') }}：</div>

											<div class="value num" @click="startBao(list)">
												{{ list.id }}
											</div>
										</div>
										<div class="formItem">
											<div class="label">{{ $t('安装位置') }}：</div>
											<div class="value">{{ list.installPositionStr }}</div>
										</div>
										<div class="formItem">
											<div class="label">{{ $t('标准工时') }}：</div>
											<div class="value">{{ list.itemHours }}</div>
										</div>
										<div class="formItem">
											<div class="label">{{ $t('创建时间') }}：</div>
											<div class="value">{{ list.createTime }}</div>
										</div>
										<div class="formItem">
											<div class="label">{{ $t('截至时间') }}：</div>
											<div class="value">{{ list.endTime }}</div>
										</div>
										<div class="btnF">
											<Checkbox v-model="list.checked" @on-change="checkBoxchange(list)" />
											<div class="btnF_box">
												<template v-if="list.status == 0 || list.status == 3">
													<span class="btn" @click="getOrder(list)" v-has="'deviceSpotCheckBrforeService'">接单</span>
													<span class="btn delbtn" @click="delItem(list)" v-has="'deviceSpotCheckDel'">删除</span>
													<span class="btn" @click="distribution(list)" v-has="'deviceSpotCheckbrforeDispath'">分配</span>
												</template>
												<template v-if="list.status == 1">
													<span class="btn delbtn" @click="delItem(list)" v-has="'deviceSpotCheckDel'">删除</span>
													<span class="btn" @click="startBao(list)" v-has="'moldSpotCheckComplete'">开始点检</span>
												</template>
												<template v-if="list.status == 4">
													<span class="btn delbtn" @click="delItem(list)" v-has="'deviceSpotCheckDel'">删除</span>
													<span class="btn" @click="startBao(list)" v-has="'deviceSpotCheckConfirm'">确认点检</span>
												</template>
												<template v-if="list.status == 2">
													<span class="btn delbtn" @click="delItem(list)" v-has="'deviceSpotCheckDel'">删除</span>
													<span class="btn" @click="startBao(list)">查看点检</span>
												</template>
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="noneList" v-else>
								<span class="img_box">
									<img src="@/assets/imgs/maintenance/nonelist.png" />
								</span>
								<span class="noneListText">{{ $t('maintenance.noData') }}</span>
							</div>
						</div>
					</TabPane>
				</Tabs>
				<div class="pageWrap" v-if="listArr && listArr.length">
					<span class="checkAll"
						>{{ $t('common.All') }}
						<Checkbox v-model="allChecked" @on-change="checAll" />
					</span>
					<Page
						:total="totalNum"
						:page-size="pageSize"
						:page-size-opts="$variable.pageSizes"
						:current="pageNum"
						@on-change="changePageNum"
						@on-page-size-change="changePageSize"
						show-sizer
						show-total
					/>
				</div>
			</div>
		</div>
		<Modal :mask-closable="false" v-model="delFaultCodeShowF" title="">
			<Row class="enableContent">
				<Col span="24" class="enableContentInner">
					<img width="95px" src="~images/event/del.png" alt="" />
				</Col>
				<Col span="24" class="enableTips">
					<span>请确认是否删除？</span>
				</Col>
			</Row>
			<div slot="footer">
				<Button type="default" @click="delFaultCodeShowF = false">{{ $t('common.Cancle') }}</Button>
				<Button type="primary" @click="removeNode">{{ $t('maintenance.Confirmed') }}</Button>
			</div>
		</Modal>

		<Modal :mask-closable="false" v-model="caseStatus" :title="`${$t('maintenance.Close')}`">
			<div class="contentBox">
				<span class="title">{{ $t('maintenance.casereson') }}</span>
				<Input v-model="caseEndReason" type="textarea" :rows="4" placeholder="请填写结案原因..." />
			</div>
			<div slot="footer">
				<Button type="default" @click="caseStatus = false">{{ $t('common.Cancle') }}</Button>
				<Button type="primary" @click="caseOk">{{ $t('maintenance.Confirmed') }}</Button>
			</div>
		</Modal>

		<Modal :mask-closable="false" class="modal-title-layout" v-model="closeOrder" :title="`${$t('fault.Receiving')}`">
			<div class="icon blue">
				<i class="iconfont zy-common-chenggong1"></i>
			</div>
			<p class="title">
				<span>{{ $t('是否接单') }}</span>
			</p>
			<div slot="footer">
				<Button type="default" @click="closeOrder = false">{{ $t('common.Cancle') }}</Button>
				<Button type="primary" @click="orderEnter" :loading="orderEnterLoading">{{ $t('maintenance.Confirmed') }}</Button>
			</div>
		</Modal>

		<signle-common-modal ref="signleCommonModal" @handleRefresh="handleRefresh" />
	</div>
</template>

<script>
import signleCommonModal from '@/views/devScene/repair/modules/signleCommonModal';
// import componentList from "../components/componentList";
import ribao from '@/assets/imgs/maintenance/ribao.png';
import ribaohui from '@/assets/imgs/maintenance/ribaohui.png';
import banbao from '@/assets/imgs/maintenance/banbao.png';
import banbaohui from '@/assets/imgs/maintenance/banbaohui.png';
import jibao from '@/assets/imgs/maintenance/jibao.png';
import jibaohui from '@/assets/imgs/maintenance/jibaohui.png';
import bannianbao from '@/assets/imgs/maintenance/bannianbao.png';
import bannianhui from '@/assets/imgs/maintenance/bannianhui.png';
import zhoubao from '@/assets/imgs/maintenance/zhoubao.png';
import zhoubaohui from '@/assets/imgs/maintenance/zhoubaohui.png';
import yuebao from '@/assets/imgs/maintenance/yuebao.png';
import yuebaohui from '@/assets/imgs/maintenance/yuebaohui.png';
import nianbao from '@/assets/imgs/maintenance/nianbao.png';
import nianbaohui from '@/assets/imgs/maintenance/nianbaohui.png';
import jishibao from '@/assets/imgs/maintenance/jishi.png';
import jishibaohui from '@/assets/imgs/maintenance/jishihui.png';
import { getDeviceList, finishCase } from '@/api/maintenance/deviceSpotCheck';
import { mapGetters } from 'vuex';
import recursion from '@/util/recursion';
import moment from 'moment/moment';

export default {
	name: 'maintenanceListPage',
	components: {
		signleCommonModal,
	},
	computed: {
		...mapGetters(['activeTabInfo']),
		index() {
			return this.tabList.findIndex((val) => val.title === this.activeTab);
		},
	},
	data() {
		return {
			orgIdList: '',
			closeOrder: false,
			allChecked: false,
			caseStatus: false,
			caseEndReason: '',
			delFaultCodeShowF: false,
			idsList: [],
			deviceNameList: [],
			centerList: [
				{ label: 'A', value: 'A' },
				{ label: 'B', value: 'B' },
				{ label: 'C', value: 'C' },
			],
			dateTimeRange: [],
			searchParams: {},
			orgList: [],
			typeInfo: '',
			levelList: [
				{ name: `${this.$t('一级点检')}`, key: 1 },
				{ name: `${this.$t('二级点检')}`, key: 2 },
				{ name: `${this.$t('三级点检')}`, key: 3 },
			],
			pageSizeOption: [10, 20, 30],
			deviceMId: '',
			loadEnd: false,
			orderEnterLoading: false,
			pageNum: 1,
			pageSize: 10,
			showInfo: true,
			inputValue: '',
			planList: [],
			listArr: [],
			targetCirlelist: [],
			deviceMIdList: [],
			circleList: [
				{
					imgGree: banbao,
					imgGray: banbaohui,
					active: false,
					text: `${this.$t('maintenance.Shift')}`,
					code: '7',
				},
				{
					imgGree: ribao,
					imgGray: ribaohui,
					active: false,
					text: `${this.$t('maintenance.Day')}`,
					code: '1',
				},
				{
					imgGree: zhoubao,
					imgGray: zhoubaohui,
					active: false,
					text: `${this.$t('maintenance.Week')}`,
					code: '2',
				},
				{
					imgGree: yuebao,
					imgGray: yuebaohui,
					active: false,
					text: `${this.$t('maintenance.Month')}`,
					code: '3',
				},
				{
					imgGree: jibao,
					imgGray: jibaohui,
					active: false,
					text: `${this.$t('maintenance.Quarter')}`,
					code: '4',
				},
				{
					imgGree: bannianbao,
					imgGray: bannianhui,
					active: false,
					text: `${this.$t('maintenance.HalfYear')}`,
					code: '5',
				},
				{
					imgGree: nianbao,
					imgGray: nianbaohui,
					active: false,
					text: `${this.$t('maintenance.Year')}`,
					code: '6',
				},
				{
					imgGree: jishibao,
					imgGray: jishibaohui,
					active: false,
					text: `${this.$t('maintenance.Time')}`,
					code: '8',
				},
			],
			tabList: [
				{ title: `${this.$t('maintenance.Tobeallocated')}`, status: 0, num: 0 },
				{
					title: '点检中',
					status: 1,
					num: 0,
				},
				// {
				//   title: `${this.$t("maintenance.Undermaintenance")}`,
				//   status: 2,
				//   num: 0,
				// },
				{ title: `${this.$t('maintenance.Tobeconfirmed')}`, status: 4, num: 0 },
				{ title: `${this.$t('maintenance.Statement')}`, status: 2, num: 0 },
				{ title: `${this.$t('maintenance.Expired')}`, status: 3, num: 0 },
				// {title:`${this.$t('maintenance.Closed')}`,status:6,num:0},
			],
			totalNum: 0,
			delObjInfo: {},
			caseRow: {},
			targetRow: {},
			activeTab: '',
			transferId: '',
			dispatchId: '',
			tarGetorder: '',
			timerId: '',
			englishStatus: false,
			userNoArr: [],
			deviceTypeList: [],
		};
	},
	activated() {
		this.getlistNum();
		this.getOrgList();
		this.getFaultCategory('设备类别');
	},
	created() {
		if (!this.activeTabInfo) {
			this.$store.commit('detail/SET_ACTIVETAB', `${this.$t('maintenance.Tobeallocated')}`);
		}
	},
	mounted() {
		if (this.activeTabInfo) {
			this.activeTab = this.activeTabInfo;
		}
		this.getlistNum();
		this.getOrgList();
	},
	methods: {
		orderEnter() {
			this.orderEnterLoading=true;
			this.axios({
				method: 'post',
				url: '/dms/devSpotCheckTask/acceptTask',
				params: {
					id: this.tarGetorder.id,
				},
			}).then((res) => {
				if (res.code === 200) {
					this.$Message.success({
						content: `${this.$t('common.OrderSuce')}`,
						duration: 6,
						closable: true,
					});
				}
				this.getlistNum();
				this.closeOrder = false;
				this.orderEnterLoading = false;
			});
		},
		getOrder(row) {
			this.tarGetorder = row;
			this.closeOrder = true;
		},
		debounceSerach(fn, delay) {
			let _this = this;
			return function f(...args) {
				if (_this.timeID) {
					clearTimeout(_this.timeID);
				}
				_this.timeID = setTimeout(() => {
					fn(args);
				}, delay);
			};
		},
		handleRemote(query) {
			if (!query) {
				return;
			}
			const fn = this.debounceSerach(() => {
				let _query = query.split('-');
				if (Array.isArray(_query)) _query = _query[0];
				this.axios({
					method: 'post',
					url: '/dms/device/page',
					data: {
						deviceMId: _query,
						// deviceNo: "",
						// assetsNo: "",
						pageSize: 10,
						pageNum: 1,
						orgCode: this.searchParams.orgCode || '',
					},
				}).then((res) => {
					if (res.code === 200) {
						this.deviceMIdList = res.data.records.map((item) => {
							item.desc = item.deviceMId + '-' + item.deviceName + '-' + item.deviceNo;
							return item;
						});
					} else {
						this.$Message.warning({
							content: res.msg,
							duration: 6,
							closable: true,
						});
					}
				});
			}, 300);
			fn();
		},
		//获取故障数据
		getFaultCategory(name) {
			this.axios({
				method: 'get',
				url: '/dms/faultCategory/dictList',
				params: { name },
			}).then((res) => {
				if (name === '设备类别') {
					this.deviceTypeList = res.data.map((item) => {
						if (item.value) return item;
					});
				}
			});
		},
		//延时查询
		timeOutgetUserNo(query) {
			clearTimeout(this.timeout);
			let isSearchF = false;
			this.timeout = setTimeout(() => {
				if (query != '') {
					for (let item of this.userNoArr) {
						if (item.empno == query || item.empno + '-' + item.realname == query || item.realname == query) {
							isSearchF = true;
						}
					}
					if (isSearchF == false) {
						this.getUserNo(query);
					}
				}
			}, 500);
		},
		getUserNo(query) {
			this.axios({
				method: 'get',
				url: '/basic/user/searchUser',
				params: {
					key: query,
				},
			}).then((res) => {
				if (res.code === 200) {
					this.userNoArr = res.data;
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		closeMance(row) {
			this.caseEndReason = '';
			this.caseRow = row;
			this.caseStatus = true;
		},
		formstaCasChange(value, selectValue) {
			if (selectValue.length > 0) {
				this.searchParams.orgCode = selectValue[selectValue.length - 1].value;
			} else {
				this.searchParams.orgCode = '';
			}
		},
		caseOk() {
			if (!this.caseEndReason) {
				this.$Message.warning('请填写结案原因!');
				return;
			}
			const data = {
				caseEndReason: this.caseEndReason,
				taskIdList: this.idsList && this.idsList.length ? this.idsList : [this.caseRow.taskId],
			};
			finishCase(data).then((res) => {
				if (res.code == 200) {
					this.getlistNum();
					this.caseStatus = false;
					this.$Message.success({
						content: '结案成功',
						duration: 4,
						closable: true,
					});
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 4,
						closable: true,
					});
				}
			});
		},
		//批量结案
		handleBatchClose() {
			this.caseStatus = true;
		},
		getDeviceNameList(deviceName) {
			this.axios({
				method: 'get',
				url: '/dms/dcmMaintainItem/selectDeviceNames',
				params: {
					deviceName,
				},
			}).then((res) => {
				if (res.code == 200) {
					this.deviceNameList = res.data.map((val) => ({
						label: val,
						value: val,
					}));
				}
			});
		},
		getDeviceList() {
			this.axios({
				method: 'get',
				url: '/dms/dmsCategory/getSelectList',
				params: {},
			}).then((res) => {
				if (res.code === 200) {
					this.centerList = res.data;
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		handleRangeChange(val) {
			if (val[0] && val[1]) {
				this.searchParams.startDate = moment(val[0]).format('YYYY-MM-DD 00:00:00');
				this.searchParams.endDate = moment(val[1]).format('YYYY-MM-DD 23:59:59');
			} else {
				this.searchParams.startDate = '';
				this.searchParams.endDate = '';
			}
		},
		getCenterList(query) {
			if (query !== '') {
				this.axios({
					method: 'get',
					url: '/dms/dcmMaintainDetail/queryPlans',
					params: {
						planName: query,
					},
				}).then((res) => {
					if (res.code === 200) {
						this.planList = res.data;
					} else {
						this.$Message.warning({
							content: res.msg,
							duration: 6,
							closable: true,
						});
					}
				});
			} else {
				this.planList = [];
			}
		},
		getOrgList() {
			this.axios({
				method: 'get',
				url: '/basic/organization/findListByToken',
				params: { level: 0 },
			}).then((res) => {
				if (res.code === 200) {
					const obj = {
						label: 'name',
						value: 'code',
						children: 'children',
					};
					this.orgList = recursion.convertTree(res.data, obj);
				} else {
					this.$Message.warning({
						content: res.msg,
						duration: 6,
						closable: true,
					});
				}
			});
		},
		removeNode() {
			this.axios({
				method: 'post',
				url: '/dms/devSpotCheckTask/delTaskByIds',
				data: this.idsList && this.idsList.length ? this.idsList : [this.delObjInfo.id],
			}).then((res) => {
				if (res.code == 200) {
					this.getlistNum();
					this.idsList = [];
					this.delFaultCodeShowF = false;
					this.$Message.success('删除成功!');
				}
			});
		},
		checAll() {
			if (this.allChecked) {
				this.listArr.forEach((val) => (val.checked = true));
				this.idsList = this.listArr.map((val) => val.id);
			} else {
				this.listArr.forEach((val) => (val.checked = false));
				this.idsList = [];
			}
		},
		checkBoxchange(row) {
			const arr = this.listArr.filter((val) => val.checked);
			if (arr && arr.length) {
				this.idsList = arr.map((val) => val.id);
			} else {
				this.idsList = [];
			}
		},
		//批量删除
		handleBatchDelete() {
			this.delFaultCodeShowF = true;
		},
		delItem(row) {
			this.delObjInfo = row;
			this.delFaultCodeShowF = true;
		},
		//批量分配
		handleBatchDispatch() {
			this.dispatchStatus = 1;
			this.$refs.signleCommonModal.show({}, 2);
		},
		//批量转单
		handleBatchTransfer() {
			this.dispatchStatus = 2;
			this.$refs.signleCommonModal.show({}, 2);
		},
		batchTransfer(row) {
			this.transferId = row.taskId;
			this.dispatchStatus = 3;
			this.$refs.signleCommonModal.show({}, 2);
		},
		//分配
		distribution(row) {
			this.dispatchId = row.id;
			this.dispatchStatus = 0;
			this.$refs.signleCommonModal.show({}, 2);
		},
		handleRefresh(a,userNames,userIds) {
			console.log(userIds);
			if (this.dispatchStatus === 0) {
				this.axios({
					method: 'post',
					// url: '/dms/dcmMaintainTask/distribute',
					url: '/dms/devSpotCheckTask/allotTask',
					params: {
						ids: this.dispatchId.toString(),
						operId: userIds[0],
						operName:userNames[0]
					},
				}).then((res) => {
					if (res.code == 200) {
						this.pageNum = 1;
						this.tactiveTab = `${this.$t('maintenance.Tobeallocated')}`;
						this.getlistNum();
						this.$Message.success({
							content: '分配成功！',
							duration: 2,
							closable: true,
						});
					} else {
						this.$Message.warning({
							content: res.msg,
							duration: 6,
							closable: true,
						});
					}
				});
			} else if (this.dispatchStatus === 1) {
				this.axios({
					method: 'post',
					url: '/dms/dcmMaintainTask/batchDistribute',
					data: {
						ids: this.idsList.join(','),
						operateEmpno: userIds.toString(),
					},
				}).then((res) => {
					if (res.code == 200) {
						this.pageNum = 1;
						this.tactiveTab = `${this.$t('maintenance.Tobeallocated')}`;
						this.getlistNum();
						this.$Message.success({
							content: '批量分配成功！',
							duration: 2,
							closable: true,
						});
					} else {
						this.$Message.warning({
							content: res.msg,
							duration: 6,
							closable: true,
						});
					}
				});
			} else if (this.dispatchStatus === 2) {
				//批量转单
				this.axios({
					method: 'post',
					url: '/dms/mobile/maintainTask/transfer',
					data: {
						taskIdList: this.idsList,
						operateEmpno: userIds.toString(),
					},
				}).then((res) => {
					if (res.code == 200) {
						this.pageNum = 1;
						this.tactiveTab = `${this.$t('maintenance.Tobeallocated')}`;
						this.getlistNum();
						this.$Message.success({
							content: '转单成功！',
							duration: 2,
							closable: true,
						});
					} else {
						this.$Message.warning({
							content: res.msg,
							duration: 6,
							closable: true,
						});
					}
				});
			} else {
				this.axios({
					method: 'post',
					url: '/dms/mobile/maintainTask/transfer',
					data: {
						taskIdList: [this.transferId],
						operateEmpno: userIds.toString(),
					},
				}).then((res) => {
					if (res.code == 200) {
						this.pageNum = 1;
						this.tactiveTab = `${this.$t('maintenance.Tobeallocated')}`;
						this.getlistNum();
						this.$Message.success({
							content: '转单成功！',
							duration: 2,
							closable: true,
						});
					} else {
						this.$Message.warning({
							content: res.msg,
							duration: 6,
							closable: true,
						});
					}
				});
			}
		},
		startBao(data) {
			this.$store.commit('detail/SET_DATING', data);
			this.$router.push({
				path: '/devScene/deviceSpotCheck/management/detail',
			});
		},
		reset() {
			this.orgIdList = '';
			this.dateTimeRange = [];
			this.typeInfo = '';
			this.searchParams = {};
			this.assetsChange();
		},
		assetsChange() {
			if (this.pageNum === 2) {
				this.pageNum = 1;
			}
			this.getlistNum();
		},
		async getlistNum() {
			let params = JSON.parse(JSON.stringify(this.searchParams));
			if (params.installPositionStr && params.installPositionStr.length) {
				params.installPositionStr = JSON.stringify(params.installPositionStr);
			} else delete params.installPositionStr;
			const { data } = await this.axios({
				url: '/dms/devSpotCheckTask/querySpotCheckTaskCountByStatus',
				method: 'POST',
				data: params,
			});

			this.getDataList();
			this.tabList.forEach((val) => (val.num = 0));
			this.tabList.forEach((item) => {
				if (data) {
					for (let val of data) {
						if (item.status == val.status) {
							item.num = val.num;
						}
					}
				}
			});
			// this.getlistType(this.tabList[i]);
		},

		findTargetarr() {
			this.targetCirlelist = [];
			this.getDataList();

			// if (obj.circleList && obj.circleList.length) {
			//   obj.circleList.forEach((item) => {
			//     item.status = obj.status;
			//     this.targetCirlelist.push(item);
			//   });
			// }
			// if (this.targetCirlelist && this.targetCirlelist.length) {
			//   this.targetCirlelist[0].active = true;

			//   this.getDataList(this.targetCirlelist[0]);
			// }
		},
		changePageSize(pageSize) {
			this.allChecked = false;
			this.idsList = [];
			this.pageSize = pageSize;
			this.findTargetarr();
		},
		changePageNum(val) {
			this.allChecked = false;
			this.idsList = [];
			this.pageNum = val;
			this.findTargetarr();
		},
		getDataList() {
			this.listArr = [];
			let params = JSON.parse(JSON.stringify(this.searchParams));
			if (params.installPositionStr && params.installPositionStr.length) {
				params.installPositionStr = JSON.stringify(params.installPositionStr);
			} else delete params.installPositionStr;
			const obj = {
				// code: this.targetRow.code,
				status: this.tabList[this.index].status,
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				...params,
			};
			const that = this;
			getDeviceList(obj).then((res) => {
				const data = res.data;
				that.listArr = data.records;
				that.totalNum = data.total;
			});
		},
		tabChange(val) {
			this.allChecked = false;
			// this.searchParams = {}
			this.idsList = [];
			this.activeTab = val;
			this.$store.commit('detail/SET_ACTIVETAB', val);
			this.pageNum = 1;
			this.listArr = [];
			this.showInfo = false;
			this.inputValue = '';
			this.tabList.forEach((item) => {
				if (item.title === this.activeTab) {
					if (item.circleList && item.circleList.length) {
						item.circleList.forEach((val) => (val.active = false));
					}
				}
			});
			const index = this.tabList.findIndex((val) => val.title === this.activeTab);

			this.assetsChange(index);
			// this.findTargetarr()
			this.$nextTick(() => {
				this.showInfo = true;
			});
		},
		swipeClick(text) {
			this.targetRow = {};
			if (text) {
				this.pageNum = 1;
				const row = this.targetCirlelist.find((val) => val.text === text);
				this.targetRow = row;
				this.tabList.forEach((item) => {
					if (item.title === this.activeTab) {
						if (item.circleList && item.circleList.length) {
							item.circleList.forEach((val) => (val.active = false));
						}
					}
				});
				this.$set(row, 'active', true);
				// this.getDataList(row)
			}
		},
	},
};
</script>

<style scoped lang="scss">
@import 'index.scss';

/deep/ .ivu-form-item-label {
	margin-bottom: 0;
}

.pageWrap {
	//position: absolute;
	//bottom: 20px;
	//left: 30%;
	display: flex;
	justify-content: flex-end;
	align-items: center;
	padding: 10px 0;
	margin-right: 10px;

	.checkAll {
		display: inline-block;
		vertical-align: middle;
		min-width: 100px;
		height: 32px;
		line-height: 30px;
		margin-right: 10px;
		text-align: center;
		list-style: none;
		background-color: #fff;
		-webkit-user-select: none;
		-moz-user-select: none;
		-ms-user-select: none;
		user-select: none;
		cursor: pointer;
		font-family: Arial;
		font-weight: 500;
		border: 1px solid #dcdee2;
		border-radius: 4px;
		transition: border 0.2s ease-in-out, color 0.2s ease-in-out;

		/deep/ .ivu-checkbox-wrapper {
			margin: 0 !important;
			padding-left: 10px;
		}
	}
}
</style>
